package com.mdb.open.epay.resource;

import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.logger.LogAnnotation;
import com.mdb.bc.web.RepeatSubmitTypeEnum;
import com.mdb.bc.web.annotation.DenyRepeatSubmit;
import com.mdb.bc.web.support.SuperResources;
import com.mdb.open.epay.domain.bo.SignBo;
import com.mdb.open.epay.domain.bo.UnsignBo;
import com.mdb.open.epay.domain.dto.epay.SignDto;
import com.mdb.open.epay.domain.dto.epay.UnsignDto;
import com.mdb.open.epay.domain.vo.epay.SignVo;
import com.mdb.open.epay.domain.vo.epay.UnsignVo;
import com.mdb.open.epay.facade.epay.SignFacade;
import com.mdb.user.LoginUserInfoHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 签约管理
 *
 * @author liuyi
 * @date 2019-11-14
 */
@RestController
@RequestMapping("")
@Api(tags = "签约管理")
public class SignResource extends SuperResources {

    @Autowired
    private SignFacade signFacade;

    @Autowired
    private LoginUserInfoHelper loginUserInfoHelper;

    @DenyRepeatSubmit(type = RepeatSubmitTypeEnum.EXCLUSIVE_SUBMIT)
    @LogAnnotation("签约绑定")
    @ApiOperation("签约绑定")
    @PostMapping("/qp/sign")
    public ResultEx<SignVo> sign(@RequestBody SignDto dto) {
        String customerCode = loginUserInfoHelper.getCustomerCode(true);
        SignBo signBo = new SignBo();
        signBo.setCustomerCode(customerCode);
        signBo.setCustType(dto.getCustType());
        signBo.setSignSerialNo(dto.getSignSerialNo());
        signBo.setBankCardNo(dto.getBankCardNo());
        signBo.setBankAccountNameE(dto.getBankAccountNameE());
        signBo.setBankAccountNameC(dto.getBankAccountNameC());
        signBo.setPhoneArea(dto.getPhoneArea());
        signBo.setPhoneNo(dto.getPhoneNo());
        signBo.setCertType(dto.getCertType().getValue());
        signBo.setCertNo(dto.getCertNo());
        signBo.setBirthDate(dto.getBirthDate());
        signBo.setCurrency(dto.getCurrency().getValue());
        signBo.setCvv2(dto.getCvv2());
        signBo.setValidDate(dto.getValidDate());
        signBo.setMsgCode(dto.getMsgCode());
        return signFacade.sign(signBo);
    }

    @DenyRepeatSubmit(type = RepeatSubmitTypeEnum.EXCLUSIVE_SUBMIT)
    @LogAnnotation("解除签约")
    @ApiOperation("解除签约")
    @PostMapping("/qp/unsign")
    public ResultEx<UnsignVo> unSign(@RequestBody UnsignDto dto) {
        String customerCode = loginUserInfoHelper.getCustomerCode(true);
        UnsignBo unsignBo = new UnsignBo();
        unsignBo.setCustomerCode(customerCode);
        unsignBo.setBankSignNo(dto.getBankSignNo());
        unsignBo.setBankSignTime(dto.getBankSignTime());
        unsignBo.setSignSerialNo(dto.getSignSerialNo());
        return signFacade.unSign(unsignBo);
    }

}
